# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=discount
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.8
pkgrel=2
pkgdesc="A Markdown implementation written in C (mingw-w64)"
arch=('any')
url="http://www.pell.portland.or.us/~orc/Code/discount/"
license=('custom:BSD')
provides=("${MINGW_PACKAGE_PREFIX}-markdown")
conflicts=("${MINGW_PACKAGE_PREFIX}-markdown")
options=('strip' 'staticlibs')
source=(http://www.pell.portland.or.us/~orc/Code/discount/${_realname}-${pkgver}.tar.gz
        discount-mingw-building.patch)
sha256sums=('db9742460c4f33cf417ef794c8e41605f8fc498697c181aa2835f6944aba7137'
            'c4960ed97fbf37eeffc2c40a9ecc07c2e2bb18aff4f6ab6b4f55142e80abdc9c')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/discount-mingw-building.patch
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  sed -e "s/m 444/m 644/g" -i configure.inc
  MSYSTEM=MINGW \
  CC=${MINGW_PREFIX}/bin/gcc.exe \
  AC_CPP_PROG=${MINGW_PREFIX}/bin/cpp.exe \
  AC_LN_PROG="cp -pR" \
  ./configure.sh \
      --prefix=${MINGW_PREFIX} \
      --enable-all-features \
      --shared

  make
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,include,lib}
  make DESTDIR="${pkgdir}" install.everything
  mv ${pkgdir}${MINGW_PREFIX}/lib/*.dll ${pkgdir}${MINGW_PREFIX}/bin/
  install -Dm644 COPYRIGHT "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
